package com.study.design.Iterator;

import java.util.ArrayList;
import java.util.List;

/**
 * 具体迭代器
 */
public class ConcreteIterator implements Iterator {

    private List list = new ArrayList();
    //定时当前游标
    public int cursor = 0;

    public ConcreteIterator(List list) {
        this.list = list;
    }

    @Override
    public Object next() {
        //返回下一个元素
        if (this.hasNext()) {
            return this.list.get(this.cursor++);
        } else {
            return null;
        }

    }

    @Override
    public boolean hasNext() {
        //判断是否到达尾部
        if (this.cursor == list.size()) {
            return false;
        } else {
            return true;
        }

    }

    @Override
    public boolean remove() {
        //删除当前元素
        this.list.remove(this.cursor);
        return true;
    }
}
